//
//  ANSliderPicCell.m
//  AttitudeNews
//
//  Created by 刘晓萌 on 15/11/23.
//  Copyright © 2015年 刘晓萌. All rights reserved.
//

#import "ANSliderPicCell.h"
#import "SDCycleScrollView.h"
#import "ANNewsModel.h"
@interface ANSliderPicCell ()<SDCycleScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIView *showView;
@property (strong,nonatomic) NSMutableArray *imagesURLStrings;
@property (strong,nonatomic) NSMutableArray *titles;
@property (strong,nonatomic) NSMutableArray *newsArr;
@end

@implementation ANSliderPicCell


/**
 * 处理model传来的值
 */
-(void)makeData{
    self.imagesURLStrings = [NSMutableArray array];
    self.titles = [NSMutableArray array];
    
    [self.imagesURLStrings addObject:self.newsModel.imgsrc];
    [self.titles addObject:self.newsModel.title_lxm];
    
    
    self.newsArr = [NSMutableArray array];
    
    [self.newsArr addObject:self.newsModel];
    
    for (NSDictionary *dic in self.newsModel.ads) {
        ANNewsModel *newsM = [[ANNewsModel alloc]init];
        [newsM setValuesForKeysWithDictionary:dic];
        
        [self.newsArr addObject:newsM];
        
        [self.imagesURLStrings addObject:newsM.imgsrc];
        [self.titles addObject:newsM.title_lxm];
    }
}

/**
 * 设置Cell内的布局及轮播图
 */
-(void)setview{
    self.contentView.backgroundColor = [UIColor colorWithRed:0.98 green:0.98 blue:0.98 alpha:0.99];
    // 情景二：采用网络图片实现
    NSArray *imagesURLStrings = self.imagesURLStrings;
    // 情景三：图片配文字
    NSArray *titles = self.titles;
    CGFloat w =  self.contentView.frame.size.width;
    //网络加载 --- 创建带标题的图片轮播器
    SDCycleScrollView * cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(1, 1, w-2, 200) imageURLStringsGroup:nil];
    cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
    cycleScrollView.delegate = self;
    cycleScrollView.titlesGroup = titles;
    cycleScrollView.dotColor = [UIColor whiteColor]; // 自定义分页控件小圆标颜色
    cycleScrollView.placeholderImage = [UIImage imageNamed:@"placeholder"];
    cycleScrollView.autoScrollTimeInterval = 10;//设置延迟时间
    [ self.showView addSubview: cycleScrollView];
    cycleScrollView.imageURLStringsGroup = imagesURLStrings;
}

#pragma mark - SDCycleScrollViewDelegate的方法

/**
 * 轮播图的点击事件
 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
    
    ANNewsModel *newsModel = self.newsArr[index];
    
    self.PushBlock(newsModel);
}


- (void)awakeFromNib {
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end
